<%-- 
    Document   : payment
    Created on : Mar 27, 2013, 5:53:27 PM
    Author     : Shaun McCready
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="org.domain.Item"%>
<%@page import="org.domain.Customer"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />

  <title>Order</title>
  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
  <script type="text/javascript" src=
  "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
  <script type="text/javascript">
//<![CDATA[
  function getParameterByName(name)
  {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  var itemname = getParameterByName('itemname');
  $(document).ready(function(){
        $('#nav li').hover(function () {
                $(this).find('.dropDown').slideToggle(200);
                $(this).toggleClass('active');
  });

                   $('#itemC').val(itemname);

        });

  //]]>
  </script>
</head>

<body>
  <div class="wrapper">
    <div id="navContainer">
      <ul class="clear" id="nav">
        <li class="first"><a class="active" href="home.jsp">Home</a></li>

        <li>
          <a href="camera.jsp">Products</a>

          <div class="dropDown">
            <div class="top"></div>

            <div class="items">
              <ul>
                <li class="first"><a href="camera.jsp">Cameras</a></li>

                <li><a href="dvd.jsp">DVD Players</a></li>

                <li class="last"><a href="tv.jsp">Televisions</a></li>
              </ul>
            </div>
          </div>
        </li>

        <li><a href="order.jsp">Order</a></li>

        <li><a  class="selected href="payment.jsp">Payment</a></li>

        <li class="last"><a href="logout">Logout</a></li>
      </ul>
    </div>
  </div>
<div class="shoppingcart" style="position:absolute; top:11px; right:25%; margin-right:0px;">
    <%
    String cart1 = request.getSession().getAttribute("cart").toString();
    int cart = Integer.parseInt(cart1);
    %>
    <img src="images/cart.png" width="30" height="30" />

    <span style="padding:0; color:silver;">Items: <%=cart%></span>

</div>
  <div id="mainContent">
    <h1>Payment</h1>

    <%

     int[] orderItems = (int[])request.getSession().getAttribute("orderItems");
     Customer cust = (Customer)request.getSession().getAttribute("cust");

     //if(orderItems == null)
     if(cust == null)
      {
    %>

<p>There currently is nothing on order.</p>

<%
    }
     else
         {
         //Customer cust = (Customer)request.getSession().getAttribute("cust");
%>
    <br/>
    <p>Here is a summary of all items ordered:</p>

	<form action="paymentProcess" method="POST" class="aligned">
	<table>
        <tr>
            <th>Item</th>
            <th>Manufacturer</th>
            <th>Quantity</th>
            <th>Cost</th>
        </tr>

	<!--Retrieve all items and loop through and display -->
    <div id="orderItems">
               <%

           ArrayList<Item> list = (ArrayList<Item>)request.getSession().getAttribute("inventory");
           double sum=0,adding=0;

           for(int i=0; i < orderItems.length; i++)
               {
               if(orderItems[i] > 0)
                   {
                   adding = list.get(i).getPrice() * orderItems[i];
                   sum = sum + adding;

           %>
           <tr>
               <td><%=list.get(i).getProduct() %></td>
               <td><%=list.get(i).getManufacturer() %></td>
               <td><%=orderItems[i] %></td>
               <td>$<%=list.get(i).getPrice()%></td>
           </tr>

            <%
                    }
               }
           %>
    </div>
	<!--end of loop-->
	
    </table>


	<strong style="margin-left:25px">The total cost for this order is : &nbsp; <span id="totalCost">$<%=(int)sum%></span></strong>
<br /><br /><br /><hr/><br/><br/>
    &nbsp; &nbsp; &nbsp;This order will be Shipped to:<br/>

    <ul style="list-style:none; margin-left:-20px;">
        <li><%=cust.getName() %></li>
        <li><%=cust.getAddress1() %></li>
        <li><%=cust.getAddress2() %></li>
        <li><%=cust.getCity() %> , <%=cust.getProvince() %> </li>
        <li><%=cust.getCountry() %> , <%=cust.getPostalCode()%></li>
    </ul>
    <!--
    John Smith<br />
	123 Main St.<br />
	Montreal, Quebec, Canada<br />
	H3N 2P2<br />
	
	<br />And Billed to:<br />
	John Smith<br />
	321 Main St.<br />
	Montreal, Quebec, Canada<br />
	H3P 2N2<br /></p>

	<br />Finalize the order by clicking on the Pay button.
    -->
    
    <button type="submit" style="margin-left:15px;">Pay</button>
  </form>
  
  <%
  }
     %>
     
  </div>

  <div id="footer">
    <center>
 <a href="home.jsp">Home</a> | <a href="camera.jsp">Products</a> | <a href="order.jsp">Order</a> | <a href=
      "payment.jsp">Payment</a> | <a href="logout">Logout</a><br />
      Copyright 2013 by Company X. All Rights Reserved.
    </center>
  </div>
</body>
</html>
